package com.example.demo.repository;

import com.example.demo.model.Classes;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;

@Repository
public interface ClassRepository extends JpaRepository<Classes, Long> {
    List<Classes> findByNameContaining(String name);
    List<Classes> findByStatus(Classes.Status status);
    
    // 添加分页搜索方法
    Page<Classes> findByNameContaining(String name, Pageable pageable);
    
    // 添加多条件搜索方法
    @Query("SELECT c FROM Classes c WHERE " +
           "(:name IS NULL OR c.name LIKE %:name%) AND " +
           "(:status IS NULL OR c.status = :status) AND " +
           "(:graduationStatus IS NULL OR c.graduationStatus = :graduationStatus)")
    Page<Classes> findByFilters(@Param("name") String name, 
                               @Param("status") Classes.Status status,
                               @Param("graduationStatus") Classes.GraduationStatus graduationStatus,
                               Pageable pageable);
                               
    // 添加按名称查找的方法（用于导入功能）
    Optional<Classes> findByName(String name);
    
    // 根据专业ID查找班级
    List<Classes> findByMajorId(Long majorId);
}